from starlette.endpoints import HTTPEndpoint
from starlette.responses import JSONResponse
from database import Session, engine
import datetime
from dao import DaoEmpWorkloadRep
from dao import DaoWorkRecord


class EmpWorkloadRep(HTTPEndpoint):
    async def get(self, request):
        session = Session()
        try:
           begin_time = request.query_params["begintime"]
           end_time = request.query_params["endtime"]
           openid = request.query_params["openid"]
           bureauid = request.query_params["bureauid"]
           return  DaoEmpWorkloadRep.get_emp_workload_rep(session, begin_time, end_time, openid, bureauid)
        finally:
            session.close()

class EmpWorkloadRepDetail(HTTPEndpoint):

    async def get(self, request):
        session = Session()
        try:
           begin_time = request.query_params["begintime"]
           end_time = request.query_params["endtime"]
           bureauid = request.query_params["bureauid"]
           flag = request.query_params["flag"]
           workid=request.query_params["workid"]
           return DaoWorkRecord.get_emp_workload_detail(session, begin_time, end_time, bureauid, flag, workid)
        finally:
            session.close()